<?php
/**
 * Email: 1057780049@qq.com.
 * User: lanjiafeng
 * Date Time: 2021/5/31 15:49
 */

namespace addons\cms\controller\wxapp;

use app\admin\model\RecoveryCategory;
use app\admin\model\Knowledge;
use function print_r;
use function var_dump;

class Content extends Base
{
    protected $noNeedLogin = ['knowledge', 'knowledgeDetail'];

    /*分类知识*/
    public function knowledge()
    {
        $list = Knowledge::where(1)
            ->order('id asc')
            ->cache(false)
            ->select();
        foreach ($list as &$row){
            $row['image'] = cdnurl($row['image'], true);
        }
        $this->success('', $list);
    }

    /*分类知识详情*/
    public function knowledgeDetail()
    {
        $id = $this->request->post('id/d');//订单id
        $knowledge = Knowledge::get($id);
        if (!$knowledge) {
            $this->error(__('分类不存在'));
        }
        $cndurl = cdnurl('', true);
        $knowledge['describecontent'] = str_replace('src="', 'src="' . $cndurl, $knowledge['describecontent']);
//        $list = Knowledge::where(1)
//            ->order('id asc')
//            ->cache(false)
//            ->select();
//        foreach ($list as &$row){
//            $row['image'] = cdnurl($row['image'], true);
//        }
        $this->success('', $knowledge);
    }

}